﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApplication1.Common;
using WindowsFormsApplication1.RSA.Dto;
using FanJiaCommon.Kits;

namespace WindowsFormsApplication1.RSA
{
    public partial class RsaForm : Form
    {
        public RsaForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var r = ACardReq.SyncEntInfo();
            MessageBox.Show(r);
            var d = JsonKit.DeserializeJsonToObject<ResultDto<Object>>(r);
            return;
            

            var company = new CompanyInfo();
            company.CompanyCode = "A0004";
            company.CompanyName = "牛逼的公司";

            var str = JsonKit.CamelCaseSerializeObject(company);
            //var str =
            //    "{\"companyCode\":\"1\",\"employeeId\":\"fj1\",\"outRefundNo\":\"fjrefund1\",\"outTradeNo\":\"fj1234567\",\"refundFee\":\"1\"}";
            var rsaHelper = new RSAHelper();
            var encryStr = rsaHelper.GetEncryptedMsg(str);

            MessageBox.Show(encryStr);

            //var bb = Encoding.Default.GetBytes(encryStr);
            //var deStr = rsaHelper.GetDecryptedMsg1(bb);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            var r = ACardReq.SyncEmployee();
            MessageBox.Show(r.Code);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            var r = ACardReq.Pay();
            MessageBox.Show(r.Code);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            var r = ACardReq.PayQuery();
            MessageBox.Show(r.Code);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            var r = ACardReq.Refund();
            MessageBox.Show(r.Code);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            var r = ACardReq.RefundQuery();
            MessageBox.Show(r.Code);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            //var rsaHelper = new RSAHelper();

            //var bt= Encoding.UTF8.GetBytes(this.textBox1.Text.Trim());
            //var r = rsaHelper.GetDecryptedMsg(bt);
            //var rStr = BitConverter.ToString(r);

            //var priKey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3ZQWutHf+umyByy9qq3KsPUycCgYAectXbIdWYHF73u9/r0ORU+oUMHoy8CYUYKf8F2jFPv27ruk+zsSj4t0LefY+jJMmM2fOEeKPJSuQMrskc+H5LGYjoISCAYaJ5I2ntC1SYJG+n4qZtari/9i+i9KaPaWXH8Y5guPwwpIiBNZ54fvpYEnknoKB6CwdE91uN4vNgnQKBgDze3+wND0M/4owcCSaG9E+1af17tH4xG3fcZJNQQfOeVuaSHHIGBIb8qpBqRYaPGubzcMQ/Uaq0Z4gD7z49idJ1Cuoxi+ykoRqo548SVv3fY9ZesNFoiLaWzOE+vZMZtxTqjc5Rx+uUjUSmg+QqmCgAD38fjeNGgOXOtt9oeQWVAoGBAODVpMrxiPWyQglaAHwGo1HjOBxtRA0pZxdud8pRSl1TckCOpHm3iWJNLbOU3unjeKX8qE4PX0e5AZ65zfoqGOaPBLbALUnwZ+BxENlm6HH5Cm4eXf2oOaSEgLa5fNiEJzFoYirO2MKkJLwDUOSB8cw8DrzO3qTe1FGQwu+tQvL7";
            //var rStr = RasBouncyCastle.DecryptByPrivateKey(this.textBox1.Text.Trim(), priKey);

            var rStr = RasBouncyCastle.RSADecryptByPrivateKey(this.textBox1.Text.Trim());

            MessageBox.Show(rStr);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            //var rsaHelper = new RSAHelper();
            //var rStr = rsaHelper.GetEncryptedMsg(this.textBox1.Text.Trim());
            //MessageBox.Show(rStr);

            var priKey = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzcCkVqrvOWXdySj3xpEzu6X6baKHmw/Lej4pKtix479V9wtMYI6YFB/HMmJCvnWp/NKWOu/q3K3/GDiOWW1LZLYWsIyb3egnTj3V855qwek6twY0eaerSsdQCpTP0ElPFwFWr0lwKxQOqVvqbeWrbTyFyD3QM1r5rTClfHr2pkcrPmCI8UWiR+nJFmfaXJC3GxI7djEy0RkZBYap+5piQx/hNXJ8U4eYIMD8AJVy/v63wysJBSwLbhSbnSdYMpR2HJIJYycPEdSzBf6jRhManJeWDyfC2jLzYJbexsftvBrx12Hysvt3q3UCOb9I5KYqvyvHXAFWEE8ovZ0Un31LmwIDAQAB";
            var rStr = RasBouncyCastle.EncryptByPublicKey(this.textBox1.Text.Trim(), priKey);

            //var rStr = RasBouncyCastle.GetNonce(this.textBox1.Text.Trim());
            //MessageBox.Show(rStr);
        }

    }
}


